package com.springcloud.configclient.payment.controller;

import com.springcloud.configclient.commons.entities.CommonResult;
import com.springcloud.configclient.commons.entities.Payment;
import com.springcloud.configclient.payment.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService service;

    @PostMapping(value = "/payment/add")
    public CommonResult add(@RequestBody Payment payment) {
        System.out.println("--------++++++++++++++++------");
        int result = service.add(payment);
        if (result > 0) {
            return new CommonResult(200, "插入成功", result);
        } else {
            return new CommonResult(444, "插入失败", null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult add(@PathVariable("id") long id) {
        System.out.println("-------------------");
        Payment payMent = service.getPayMent(id);
        if (payMent != null) {
            return new CommonResult(200, "查询成功", payMent);
        } else {
            return new CommonResult(444, "查询失败", null);
        }
    }
}
